package com.medusa.aps.business.modules.demand.model.input;

import com.medusa.aps.business.model.enums.SchedulingStatusEnum;
import com.medusa.aps.business.modules.demand.mp.entity.OrderInformation;
import com.medusa.aps.business.common.model.resp.SystemCode;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.hibernate.validator.constraints.Range;

import java.util.List;

/**
 * @author miskw
 * @date 2024/1/2
 */
@Data
@Schema(description = "更新订单优先级实体")
public class OrderIncrementParam {
    /**
     * 订单id
     */
    @Schema(description = "订单id")
    @NotNull(message = "订单id不能为空")
    private Integer id;
    /**
     * 订单优先级
     */
    @Schema(description = "订单优先级")
    @NotNull(message = "订单优先级不能为空")
    @Range(min = 1, max = 10, message = "订单优先级取值范围为1-10")
    private Integer orderPriority;

    public void validEditPriorityOrderStatus(boolean isDemandOrder, OrderInformation information) {
        if (!information.getSchedulingStatus().isEditable() && isDemandOrder) {
            throw SystemCode.PARAM_VALID_ERROR.msgEx("需求订单只能编辑未排产订单");
        }
        if (!List.of(SchedulingStatusEnum.NOTARRANGED, SchedulingStatusEnum.ARRANGED).contains(information.getSchedulingStatus())
                && !isDemandOrder) {
            throw SystemCode.PARAM_VALID_ERROR.msgEx("调整排程只能编辑未排产、已排产订单");
        }
    }
}
